package nancal.mp.db.mongo.entity.dev

import nancal.mp.db.mongo.JenkinsLanguageEnum
import nbcp.base.db.IdCodeName
import nbcp.base.db.IdNameUrl
import nbcp.base.db.annotation.Cn
import nbcp.base.db.annotation.DbEntityGroup
import nbcp.base.db.annotation.DbEntityIndex
import nbcp.base.db.annotation.DbEntityIndexes
import nbcp.base.extend.HasValue
import nbcp.base.model.BaseMarkEntity
import org.springframework.data.mongodb.core.mapping.Document

@Document
@DbEntityGroup("dev")
@Cn("Git仓库")
@DbEntityIndexes(DbEntityIndex("updateAt", unique = false))
open class GitData(
        @Cn("集群") var clusterCode: String = "",
        @Cn("server") var server: IdNameUrl = IdNameUrl(),
        @Cn("accessToken") var accessToken: String = "",
        @Cn("语言") var language: JenkinsLanguageEnum = JenkinsLanguageEnum.Java,
        @Cn("开发语言的版本，如 1.8,11,17") var languageVersion: String = "",

        @Cn("是否是lib库")
        var isLib: Boolean = false,
        /**
         * Git完整路径=server.host + this.path
         */
        @Cn("Git路径")
        var path: String = "",
        var name: String = "",
        @Cn("子文件夹") var folders: MutableList<GitFolderData> = mutableListOf(),
        @Cn("产品线") var productLine: IdCodeName = IdCodeName()
) : BaseMarkEntity() {

    val url: String
        get() {
            return server.url + this.path;
        }

    val group: String
        get() {
            var sects = this.path.split("/").filter { it.HasValue };
            if (sects.size < 2) {
                return "";
            }
            return sects[0];
        }
    val project: String
        get() {
            var sects = this.path.split("/").filter { it.HasValue };
            if (sects.size < 2) {
                return "";
            }
            return sects[1].split(".git")[0];
        }

}